package com.bjfu.eduservice.controller;


import com.bjfu.common_utils.R;
import com.bjfu.eduservice.entity.EduChapter;
import com.bjfu.eduservice.entity.chapter.ChapterVo;
import com.bjfu.eduservice.service.EduChapterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author Guli
 * @since 2020-07-04
 */
@RestController
@RequestMapping("/eduservice/chapter")
//@CrossOrigin
@Api(tags = "章节管理")
public class EduChapterController {
    @Autowired
    private EduChapterService chapterService;

    // 根据课程ID课程大纲列表
    @ApiOperation("根据课程ID课程大纲列表")
    @GetMapping("getChapterVideo/{courseId}")
    public R getChapterVideo(
            @ApiParam(name = "courseId",value = "课程Id",required = true)
            @PathVariable String courseId
    ) {
        List<ChapterVo> list = chapterService.getChapterListByCourseId(courseId);
        return R.ok().data("allChapterVideo",list);
    }

    // 添加章节
    @ApiOperation("添加章节")
    @PostMapping("addChapter")
    public R addChapter(@RequestBody EduChapter eduChapter){
        chapterService.save(eduChapter);
        return R.ok();
    }

    // 根据章节id查询章节
    @ApiOperation("根据章节id查询")
    @GetMapping("getChapter/{chapterId}")
    public R getChapterInfo(
            @PathVariable String chapterId
    ){
        EduChapter chapter = chapterService.getById(chapterId);
        return R.ok().data("chapter",chapter);
    }

    // 修改章节
    @ApiOperation("修改章节")
    @PostMapping("updateChapter")
    public R updateChapter(@RequestBody EduChapter eduChapter){
        chapterService.updateById(eduChapter);
        return R.ok();
    }

    // 根据id删除章节
    @ApiOperation("根据id删除章节")
    @DeleteMapping("deleteChapter/{chapterId}")
    public R deleteChapterInfo(
            @PathVariable String chapterId
    ){
        chapterService.deleteChapter(chapterId);
        return R.ok();
    }

}

